package com.jianguo.web.controller.order;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianguo.common.annotation.Log;
import com.jianguo.common.core.controller.BaseController;
import com.jianguo.common.core.domain.AjaxResult;
import com.jianguo.common.enums.BusinessType;
import com.jianguo.order.domain.PzOrderStepRecord;
import com.jianguo.order.service.IPzOrderStepRecordService;
import com.jianguo.common.utils.poi.ExcelUtil;
import com.jianguo.common.core.page.TableDataInfo;

/**
 * 服务记录Controller
 *
 * @author xjj
 * @date 2024-04-11
 */
@RestController
@RequestMapping("/order/record")
public class PzOrderStepRecordController extends BaseController
{
    @Autowired
    private IPzOrderStepRecordService pzOrderStepRecordService;

    /**
     * 查询服务记录列表
     */
    @PreAuthorize("@ss.hasPermi('order:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(PzOrderStepRecord pzOrderStepRecord)
    {
        startPage();
        List<PzOrderStepRecord> list = pzOrderStepRecordService.list(new LambdaQueryWrapper<PzOrderStepRecord>()
                .eq(PzOrderStepRecord::getOrderId, pzOrderStepRecord.getOrderId()).orderByAsc(PzOrderStepRecord::getSort));
        return getDataTable(list);
    }

    /**
     * 导出服务记录列表
     */
    @PreAuthorize("@ss.hasPermi('order:record:export')")
    @Log(title = "服务记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PzOrderStepRecord pzOrderStepRecord)
    {
        List<PzOrderStepRecord> list = pzOrderStepRecordService.selectPzOrderStepRecordList(pzOrderStepRecord);
        ExcelUtil<PzOrderStepRecord> util = new ExcelUtil<PzOrderStepRecord>(PzOrderStepRecord.class);
        util.exportExcel(response, list, "服务记录数据");
    }

    /**
     * 获取服务记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(pzOrderStepRecordService.getById(id));
    }

    /**
     * 新增服务记录
     */
    @PreAuthorize("@ss.hasPermi('order:record:add')")
    @Log(title = "服务记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PzOrderStepRecord pzOrderStepRecord) {
        return toAjax(pzOrderStepRecordService.save(pzOrderStepRecord));
    }

    /**
     * 修改服务记录
     */
    @PreAuthorize("@ss.hasPermi('order:record:edit')")
    @Log(title = "服务记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PzOrderStepRecord pzOrderStepRecord) {
        return toAjax(pzOrderStepRecordService.updateById(pzOrderStepRecord));
    }

    /**
     * 删除服务记录
     */
    @PreAuthorize("@ss.hasPermi('order:record:remove')")
    @Log(title = "服务记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(pzOrderStepRecordService.removeByIds(Arrays.asList(ids)));
    }
}
